package com.principle.strategy;

/**
 * 执行策略模式的环境
 * @description:交通出行方式
 * @author zhonghong.zhangxg
 * @date 2016年7月12日下午7:29:19
 */
public class TrafficCalculator {
    ICalculateStrategy mStrategy;

    public ICalculateStrategy getStrategy() {
        return mStrategy;
    }

    public void setStrategy(ICalculateStrategy strategy) {
        this.mStrategy = strategy;
    }
    
    public int calculatePrice(int km) {
        return mStrategy.calculatePrice(km);
    }
    
    /**
     * 客户端测试
     * @param args
     */
    public static void main(String[] args) {
        TrafficCalculator calculator = new TrafficCalculator();
        calculator.setStrategy(new BusStrategy());
        calculator.calculatePrice(5);
        
        calculator.setStrategy(new SubwayStrategy());
        calculator.calculatePrice(5);
    }
}
